class_name Attack_D4 # 类似于近战攻击，对于所在的位置有一个相对打击范围，一次可以向四个方向之一打出的攻击
extends Attack

func calculate_max_dmg(coord_in, enemy_type): # 参数：释放时所处的位置，计分的受击类型
	var max_damage = 0
	var best_attck_points
	var best_dmgs
	var damage_in_a_hit
	var t
	var attack_points_in_a_hit
	var dmgs_in_a_hit
	# 四向的变换矩阵
	var rotate_matrix = [
		[[1, 0],[0, 1]],
		[[0, 1],[ - 1, 0]],
		[[ - 1, 0],[0, - 1]],
		[[0, - 1],[1, 0]]
	]

	# 一个基准点
	for base_point in base_point_list:
		# 一个方向
		for i in range(4): # 四向
			damage_in_a_hit = 0
			t = 0
			attack_points_in_a_hit = []
			dmgs_in_a_hit = []
		
			for rela_point in rela_point_list:
				var bias = [base_point[0] + rela_point[0],base_point[1] + rela_point[1]]
				# 计算攻击的最终落点，需要乘以旋转矩阵
				var x = coord_in[0] + rotate_matrix[i][0][0] * bias[0] + rotate_matrix[i][0][1] * bias[1]
				var y = coord_in[1] + rotate_matrix[i][1][0] * bias[0] + rotate_matrix[i][1][1] * bias[1]
				# 累计一击中造成的伤害总量，计算时不能超出棋盘格
				if 0 <= x and x < Chessboard.BOARD_SIZE and 0 <= y and y < Chessboard.BOARD_SIZE:
					attack_points_in_a_hit.append([x, y])
					dmgs_in_a_hit.append(rela_point_dmg[t])
					if Chessboard.board_array[x][y] != null and Chessboard.board_array[x][y].camp == enemy_type:
						damage_in_a_hit += rela_point_dmg[t]
				t += 1
			# 记录最大值
			if damage_in_a_hit > max_damage:
				max_damage = damage_in_a_hit
				best_attck_points = attack_points_in_a_hit.duplicate(true)
				best_dmgs = dmgs_in_a_hit.duplicate(true)

	return [max_damage, best_attck_points, best_dmgs]
